package com.csun.cmny.provider.model.enums.device;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-03-06 10:27
 * @Description:
 */
public enum DeviceStatusEnum {

    /**
     * online dmc device status enum.
     */
    /*
     * 在线
     */
    ONLINE("online", "在线"),
    /**
     * 离线
     */
    OFFLINE("offline", "离线");

    /**
     * The Key.
     */
    String key;
    /**
     * The Value.
     */
    String value;

    DeviceStatusEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    /**
     * Gets key.
     *
     * @return the key
     */
    public String getKey() {
        return key;
    }

    /**
     * Gets value.
     *
     * @return the value
     */
    public String getValue() {
        return value;
    }

    /**
     * 获取key获取value
     *
     * @param key key
     *
     * @return value value
     */
    public static String getValue(String key) {
        for (DeviceStatusEnum ele : DeviceStatusEnum.values()) {
            if (key.equals(ele.getKey())) {
                return ele.getValue();
            }
        }
        return null;
    }

    /**
     * 根据key获取该对象
     *
     * @param key key
     *
     * @return this enum
     */
    public static DeviceStatusEnum getEnum(String key) {
        for (DeviceStatusEnum ele : DeviceStatusEnum.values()) {
            if (key.equals(ele.getKey())) {
                return ele;
            }
        }
        return null;
    }

    /**
     * 获取List集合
     *
     * @return List list
     */
    public static List<DeviceStatusEnum> getList() {
        return Arrays.asList(DeviceStatusEnum.values());
    }


    /**
     * 获取map类型集合
     *
     * @return Map类型List集合 map 2 list
     */
    public static List<Map<String, String>> getMap2List() {
        List<Map<String, String>> list = Lists.newArrayList();
        for (DeviceStatusEnum ele : DeviceStatusEnum.values()) {
            Map<String, String> map = Maps.newHashMap();
            map.put("key", ele.getKey());
            map.put("value", ele.getValue());
            list.add(map);
        }
        return list;
    }

}